CC = gcc

I_FLAGS = -I./include -I ~/my_software/cmark-gfm/src -I ~/my_software/cmark-gfm/build/src
L_FLAGS =-L/home/cat/my_software/cmark-gfm/build/extensions -L/home/cat/my_software/cmark-gfm/build/src
LIB_FLAGS =-lcmark-gfm -lcmark-gfm-extensions
OHTER_FLAGS=

SRCDIR = ./src
INCDIR = ./include
OBJDIR = ./obj
BINDIR = ./bin

# 通配符“%”，表示任意长度的字串
SRCS = $(wildcard $(SRCDIR)/*.c)
OBJS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRCS))

TARGET = $(BINDIR)/tr 

# # Check if the directory exists
# ifeq (,$(wildcard $(DIR_TO_CREATE)))
#     # If the directory does not exist, create it
#     $(shell mkdir -p $(DIR_TO_CREATE))
# endif


# $@表示目标，$^表示依赖，$< 表示第一个依赖
$(TARGET): $(OBJS)
	$(CC) $^ -o $@ $(L_FLAGS) $(LIB_FLAGS)

$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR) $(BINDIR) 
	@echo build obj: $@
	$(CC) -c $< -o $@ $(I_FLAGS) $(OHTER_FLAGS)

$(OBJDIR):
	mkdir -p $(OBJDIR)

$(BINDIR):
	mkdir -p $(BINDIR)

.PHONY: clean
clean:
	rm -rf $(OBJDIR) $(BINDIR)

.PHONY: test
test:
	./bin/tr ./test/test.html -p var=hah -p error=build.bash -p test.md=test/test.md
# 	@echo $(SRCS)
# 	@echo $(OBJS)
